using UnityEngine;
using System.Collections;
using System.IO;


public class Menu : MonoBehaviour {

    int id = 1;
    GameObject fade_in;
    GameObject fade_out;
    GameObject button;

    StreamWriter stream_writer;
    StreamReader stream_reader;

    float count_change_scene;

    string fileName = "Ranking.txt";

    void Start()
    {
        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");


        Mesh mesh = Quad.Create(4.0f, 3.0f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};

        fade_in = new GameObject("Fade_In", typeof(Fade_In));
        Fade_Out.fade_out_begin = false;
        Fade_Out.fade_out_terminated = false;
    }

    void Update()
    {
		if (Fade_Out.fade_out_terminated)
		{
			Application.LoadLevel("Create_Profile");
		}
    }

    void OnGUI()
    {
        if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 15 - 160, 160, 30), "Criar Perfil"))
        {
			if (!Fade_Out.fade_out_begin)
			{
				fade_out = new GameObject("Fade_Out", typeof(Fade_Out));
			}
        }

        if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 15 - 40, 160, 30), "Carregar"))
        {
			Database.Load_Database();
        }

        if (GUI.Button(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 15, 160, 30), "Salvar"))
        {
			Database.Save_Database();
        }
    }
}
